import Vue from 'vue'
import App from './App.vue'
import router from './router'
import Router from 'vue-router'
import store from './store'
import axios from 'axios'

import echarts from 'echarts'
import md5 from 'js-md5';
Vue.prototype.$md5 = md5;
Vue.prototype.$echarts = echarts

import './rem'

import Vant from 'vant';
import 'vant/lib/index.css';
Vue.use(Vant);

import VideoPlayer from 'vue-video-player'
Vue.use(VideoPlayer)
require('vue-video-player/src/custom-theme.css')

//瀑布流
import waterfall from 'vue-waterfall2'
Vue.use(waterfall)

//swiper
import VueAwesomeSwiper from 'vue-awesome-swiper'
import 'swiper/swiper-bundle.css'
Vue.use(VueAwesomeSwiper, /* { default options with global component } */)

//复制
import VueClipboard from 'vue-clipboard2'
Vue.use(VueClipboard)

Vue.use(Router)

const originalPush = Router.prototype.push
Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

// 添加响应拦截器
axios.interceptors.response.use(function (response) {
  // 对响应数据做点什么
  if (response.data.status == -2) {
    localStorage.token = ''
    window.location.href = window.location.href.split('/#/')[0] + '/#/login'
  }
  return response;
})

// 添加请求拦截器
axios.interceptors.request.use(function (config) {
  // 在发送请求之前做些什么
  config.headers['x-access-token'] = localStorage.token || ''
  config.headers['x-access-appid'] = 'chengwu_app'
  return config
}, function (error) {
  // 对请求错误做些什么
  return Promise.reject(error);
});

router.beforeEach((to, from, next) => {
  document.title = to.meta.title
  // if (to.name != 'login' && to.name != 'home' && !localStorage.token && (to.name.indexOf('Detail') == -1)) {
  //   window.location.href = window.location.href.split('/#/')[0] + '/#/login'
  // } else {
  next();
  // }
})


Vue.config.productionTip = false

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
